package mlta.activities;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class CoursesActivity extends Activity {
	
	protected Button btn_help;
	
	protected Button btn_exit;
	
	protected Button btn_home;
	
	protected Button btn_refresh;
	
	protected Button btn_search;
	
	protected Button btn_new;
	
	protected Button btn_old;
	
	protected Button btn_back;
	
	protected String username;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.courses);
        
        username = getIntent().getStringExtra("username");
        
        btn_help = (Button) findViewById(R.id.courses_help);
        btn_exit = (Button) findViewById(R.id.courses_exit);
        btn_home = (Button) findViewById(R.id.courses_home);
        btn_refresh = (Button) findViewById(R.id.courses_refresh);
        btn_search = (Button) findViewById(R.id.courses_search);
        btn_new = (Button) findViewById(R.id.courses_new);
        btn_old = (Button) findViewById(R.id.courses_old);
        btn_back = (Button) findViewById(R.id.courses_back);
        
        btn_help.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Toast.makeText(getApplicationContext(), "Feature not ready yet!!!", Toast.LENGTH_LONG).show();
			}
			
		});
        
        btn_exit.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				System.exit(0);
			}
			
		});
        
        btn_home.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(CoursesActivity.this, CoursesActivity.class);
				intent.putExtra("username", username);
				CoursesActivity.this.startActivity(intent);
				System.exit(0);
			}
			
		});
        
        btn_refresh.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(CoursesActivity.this, CoursesActivity.class);
				intent.putExtra("username", username);
				CoursesActivity.this.startActivity(intent);
				System.exit(0);;
			}
			
		});
        
        btn_search.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(CoursesActivity.this, SearchActivity.class);
				intent.putExtra("username", username);
				intent.putExtra("tipo", 1);
				CoursesActivity.this.startActivity(intent);
				System.exit(0);
			}
			
		});
        
        btn_new.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Toast.makeText(getApplicationContext(), "Please, first choose a course!", Toast.LENGTH_LONG).show();
			}
			
		});
        
        btn_old.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Toast.makeText(getApplicationContext(), "No more courses!", Toast.LENGTH_LONG).show();
			}
			
		});
        
        btn_back.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				System.exit(0);
			}
			
		});
        
        ListView listView = (ListView) findViewById(R.id.courses_list);
        
        ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
        
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("course", "Fundamentos de Interação Usuário-Computador");
        map.put("unread", "(8)");
        list.add(map);

        map = new HashMap<String, String>();
        map.put("course", "Fundamentos de Sistemas Hipermídia e Web");
        map.put("unread", "(0)");
        list.add(map);
        
        map = new HashMap<String, String>();
        map.put("course", "Fundamentos de Multimídia");
        map.put("unread", "(0)");
        list.add(map);
        
        map = new HashMap<String, String>();
        map.put("course", "Engenharia de Software");
        map.put("unread", "(0)");
        list.add(map);
        
        map = new HashMap<String, String>();
        map.put("course", "Teste de Software");
        map.put("unread", "(0)");
        list.add(map);
        
        SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.course,
                new String[] {"course", "unread"}, new int[] {R.id.label, R.id.count});

        listView.setAdapter(adapter);
        
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				Intent intent = new Intent(CoursesActivity.this, CoursesTopicActivity.class);
				intent.putExtra("id", id);
				intent.putExtra("username", username);
				CoursesActivity.this.startActivity(intent);
				System.exit(0);
			}
			
		});
        
    }
    
    @Override
    public void onBackPressed() {
		System.exit(0);
    } 
    
}